{% extends "kadmin/base.html" %}

{% block content_title %}
<h1>Elastic Search - Index Browser of Doom</h1>
{% endblock %}

{% block content %}
  <section>
    <h1>Find a specific item</h1>
    <form method="GET">
      <label for="bucket-field">Model:</label>
      <select name="bucket" id="bucket-field">
        {% for bucket in buckets %}
          <option value="{{ bucket }}"{% if requested_bucket == bucket %} selected{% endif %}>{{ bucket }}</option>
        {% endfor %}
      </select>
      <label for="id-field">ID:</label>
      <input type="text" name="id" id="id-field" value="{{ requested_id }}">
      <input type="Submit">
    </form>
  </section>

  {% if requested_data %}
    <section>
      <h1>Item {{ requested_data.id }} from {{ requested_bucket }}</h1>
      <table>
        <thead>
          <tr>
            <th>key</th>
            <th>value</th>
          </tr>
        </thead>
        <tbody>
          {% for key, val in requested_data.items %}
            <tr>
              <th>{{ key }}</th>
              <td>{{ val }}</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </section>
  {% else %}
    <section>
      <h1>Most recently indexed items per bucket</h1>
      {% for cls_name, items in last_20_by_bucket %}
        <h2>{{ cls_name }}</h2>
        <table>
          <thead>
            <tr>
              <th>id</th>
              <th>title</th>
              <th>indexed on ({{ settings.TIME_ZONE }})</th>
            </tr>
          </thead>
          <tbody>
            {% for item in items %}
              <tr>
                <td><a href="?bucket={{ cls_name }}&id={{ item.id }}">{{ item.id }}</a></td>
                {# cheating here because only one of these is filled, but #}
                {# in django templates, you get an empty string if it's #}
                {# not there. #}
                <td>{{ item.question_title }}{{ item.post_title }}{{ item.document_title }}</td>
                <td>{{ item.indexed_on }}</td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      {% endfor %}
    </section>
  {% endif %}
{% endblock %}
